package com.suse.lhw.hms.authserver.controller;

import com.suse.lhw.hms.authserver.domin.URole;
import com.suse.lhw.hms.authserver.exception.BusinessException;
import com.suse.lhw.hms.authserver.service.URoleService;
import lombok.Value;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.relation.Role;
import java.util.List;

/**
 * @ProjectName: health_manage_system
 * @Package: com.suse.lhw.hms.authserver.controller
 * @ClassName: HelloDemoController
 * @Description: java类作用描述
 * @Author: 李鸿炜
 * @CreateDate: 2020/4/1 10:43
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/4/1 10:43
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@RestController
public class HelloDemoController {
    public URoleService getuRoleService() {
        return uRoleService;
    }

    @Autowired
    public void setuRoleService(URoleService uRoleService) {
        this.uRoleService = uRoleService;
    }

    URoleService uRoleService;
    String port = "8080";

    @GetMapping("testdemo")
    public String testDemo(@RequestParam String name) {

        System.out.println("now this is authserver helloDemoContrlller");
        return "hello" + name + "your port is " + port;
    }

    @GetMapping("hello")
    public String toHello() {
        System.out.println("dklsfj");
        return "hello";
    }

    @GetMapping("loadRoleList")
    public String loadRoleList(@RequestParam String id) {
        String s = null;
        List<URole> list = uRoleService.seleallRolesByUserId(id);
        for (URole uRole : list) {
            if (list.isEmpty())
                System.out.println("list is empty!!!!");
            System.out.println(uRole.toString());
            s += uRole.getName() + '\n';
        }
        return s;
    }

    @RequestMapping(value = "err")
    public void error() {
        throw new BusinessException(400, "业务异常错误信息");
    }

    @RequestMapping(value = "err2")
    public void error2() {
        throw new NullPointerException("手动抛出异常信息");
    }

    @RequestMapping(value = "err3")
    public int error3() {
        int a = 10 / 0;
        return a;
    }
}
